
function register() {
    // js数据类型 数字，数组，字符串，布尔，对象
    let data={
        username:$("#usernames").val(),
        password:$("#password").val(),
        code:$("#code").val(),
        phone:$("#phone").val(),
        sex:$("input[name='sex']:checked").val(),
        birthday:$("#birthday").val(),
        hobby:JSON.stringify((aihao())),
        introduce:$("#introduce").val()
        };
    let da=myAjax("/userregister",data,"post");
    if (da==1){
        // window.location.href="/back/login.html";
        alert("注册成功");
        $('#reght').load('/back/userManage.html')//window.open 页面跳转
    } else if (da==4) {
        alert("用户名已存在");
    }else {
        alert("注册失败");
    }
}

function aihao() {
    let hb=[];
    $("input:checkbox[name='hobby']").each(function (){
        if ($(this).prop("checked")) {
            hb.push($(this).val());
        }
    })
    return hb;
}
//判断输入密码格式是否正确
function ifPassword() {
    let regb=/^[a-zA-Z0-9]{5,10}$/;
    let password=document.getElementById("password").value;
    if (!regb.test(password)) {
        document.getElementById("password").focus();//鼠标焦点位置
        document.getElementById("passwordTip").innerHTML="你输入的密码格式不正确";
        document.getElementById("passwordTip").style.color="red";
    }else {
        document.getElementById("passwordTip").innerHTML="";
    }
}
//判断输入用户名格式是否正确
function ifusernames() {
    let rega=/^[a-zA-Z0-9]{5,10}$/;
    let usernames=document.getElementById("usernames").value;
    if (!rega.test(usernames)) {
        document.getElementById("usernames").focus();//鼠标焦点位置
        document.getElementById("usernamesTip").innerHTML="你输入的用户名格式不正确";
        document.getElementById("usernamesTip").style.color="red";
    }else {
        document.getElementById("usernamesTip").innerHTML="";
    }
}


//判断两次密码
function  checkpassword() {    //let局部变量      var 全局变量
    let password=document.getElementById("password").value;
    let repassword=document.getElementById("repassword").value;
    if (password != repassword){
        document.getElementById("repasswordTip").innerHTML="密码与原密码不一样";
        document.getElementById("repasswordTip").style.color="red";
    }else {
        document.getElementById("repasswordTip").innerHTML="";
    }
}









